﻿var view = view || {};
view.navigator = function () {
    function navigatePrivate(event) {
        $('.pageNavigator').removeClass('selectedNavigator');
        var sender = event.srcElement || event.target;
        $(sender).addClass('selectedNavigator');
        navigateToPage($(sender).attr('data-page-id'));
    }
    function navigateToPage(pageId) {
        $('.header').hide();
        $('.page').hide();
        //Display Header
        $('#' + $('#' + pageId).attr('data-header-id')).show();
        $('#' + pageId + ' .page').show(0, function () {
            if (view.pages[pageId]) {
                view.pages[pageId].load();
            }
        });
    }
    function navigateToDefault() {
        navigateToPage($($('.selectedNavigator').get(0)).attr('data-page-id'));
    }
    return {
        navigate: navigatePrivate,
        navigateToDefault: navigateToDefault,
        bindClick: function () {
            $('.pageNavigator').click(view.navigator.navigate);
        }
    }
} ();
view.loadPages = function () {
    var loc = window.location.href;
    var htmlSrc;
    var alldatasrc = $('[data-src]');
    var lastIndex = alldatasrc.length;
    var loadIndex = 0;
    for (var i = 0; i < alldatasrc.length; i++) {
        if (loc.indexOf('Default.htm' != -1)) {
            htmlSrc = loc + $(alldatasrc[i]).attr('data-src');
        }
        else {
            htmlSrc = loc.replace('Default.htm', $(value).attr('data-src'));
        }
        $(alldatasrc[i]).load(htmlSrc, null, function callback() {
            loadIndex = loadIndex + 1;
            if (loadIndex == lastIndex) {
                view.navigator.navigateToDefault();
                view.navigator.bindClick();
            }
        });
    }
}
view.pages = {};